package org.zoomdev.zoom.dao.adapters.parameter;

import org.zoomdev.zoom.dao.adapters.DataAdapter;
import org.zoomdev.zoom.dao.adapters.ParameterAdapter;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class WrappedStatementAdapter implements ParameterAdapter {


    final DataAdapter dataAdapter;
    final ParameterAdapter parameterAdapter;

    public WrappedStatementAdapter(DataAdapter dataAdapter, ParameterAdapter parameterAdapter) {
        this.dataAdapter = dataAdapter;
        this.parameterAdapter = parameterAdapter;
    }


    @Override
    public void setNonnullParameter(PreparedStatement ps, int index, Object data) throws SQLException {
        Object value = dataAdapter.toDbValue(data);
        parameterAdapter.setNonnullParameter(ps, index, value);
    }
}
